package zconvert

import (
	"strconv"
	"venus/util/ztype"
)

/* -----泛型----- */

func ToStr[T ztype.UtInteger](t T) string {
	return strconv.FormatInt(int64(t), 10)
}
func IToStr[T ztype.UtInt](t T) string {
	return strconv.FormatInt(int64(t), 10)
}
func UToStr[T ztype.UtUint](t T) string {
	return strconv.FormatUint(uint64(t), 10)
}

/* ----- string -> number ----- */

func ToInt(str string) int {
	if value, err := strconv.Atoi(str); err == nil {
		return value
	}
	return 0
}
func ToInt32(str string) int32 {
	return int32(ToInt(str))
}
func ToInt64(str string) int64 {
	if value, err := strconv.ParseInt(str, 10, 64); err == nil {
		return value
	}
	return 0
}
func IntToStr(value int) string {
	return strconv.Itoa(value)
}
func Int32ToStr(value int32) string {
	return IntToStr(int(value))
}
func Int64ToStr(value int64) string {
	return strconv.FormatInt(value, 10)
}
